import request, { $http } from '@/utils/request';
import settings from '@/settings'

const { pagination } = settings

const formatParams = (params = {}) => {
	return {
		...pagination,
		...params
	}
}

export async function download(params) {
	return request('download', {
		params,
		type: true,
		prefix: '/file/'
	})
}
export async function years(params) {
	return request('task/years', {
		params
	})
}

export async function login(data) {
	return $http.post('login', {
		data
	})
}
export async function loguser() {
	return request('loguser')
}
export async function logout() {
	return request.post('logout')
}

export async function user(params) {
	return request('user', {
		params
	})
}
export async function users(params) {
	const data = formatParams(params)
	return request.post('users', {
		data
	})
}

export async function role(params) {
	return request('role', {
		params
	})
}
export async function roles(params) {
	const data = formatParams(params)
	return request.post('roles', {
		data
	})
}
export async function all_roles() {
	return request('roles')
}

export async function unit(params) {
	return request('unit', {
		params
	})
}
export async function units(params) {
	const data = formatParams(params)
	return request.post('units', {
		data
	})
}
export async function all_units() {
	return request('units')
}

export async function week_task(params) {
	return request('week/task', {
		params
	})
}
export async function week_tasks(params) {
	const data = formatParams(params)
	return request.post('week/tasks', {
		data
	})
}

export async function issue_task(params) {
	return request('issue/task', {
		params
	})
}
export async function issue_tasks(params) {
	const data = formatParams(params)
	return request.post('issue/tasks', {
		data
	})
}

export async function folder(params) {
	return request('folder', {
		params
	})
}
export async function folders(params) {
	const data = formatParams(params)
	return request.post('folders', {
		data
	})
}

export async function file(params) {
	return request('file', {
		params
	})
}
export async function files(params) {
	const data = formatParams(params)
	return request.post('files', {
		data
	})
}

export async function field(params) {
	return request('field', {
		params
	})
}
export async function fields(params) {
	const data = formatParams(params)
	return request.post('fields', {
		data
	})
}

export async function analysis(params) {
	const data = formatParams(params)
	return request.post('analysis', {
		data
	})
}

export async function modules() {
	return request('modules')
}

export async function logs(params) {
	const data = formatParams(params)
	return request.post('logs', {
		data
	})
}